package com.shell.arouter.demo.multitype;

import android.widget.TextView;

import androidx.annotation.NonNull;

import com.durian.base.utils.LogUtils;
import com.durian.base.utils.ToastUtils;
import com.durian.ui.adapter.multi.ItemViewProvider;
import com.durian.ui.adapter.multi.MultiItemViewHolder;
import com.durian.ui.adapter.multi.MultiItemViewProvider;
import com.durian.ui.adapter.multi.OnItemClickListener;
import com.henanjianye.soon.communityo2o2.R;

/**
 * 说明：MoreOne
 * <p/>
 * 作者：fanly
 * <p/>
 * 类型：Class
 * <p/>
 * 时间：2019-11-12 16:57
 * <p/>
 * 版本：version 1.0
 */
public class MoreTwo extends MultiItemViewProvider<MoreTwoBean> {

    public MoreTwo(){
        with(new MoreA().setOnItemClickListener(new OnItemClickListener<MoreTwoBean>() {
            @Override
            public void onItemClick(int position, MoreTwoBean item) {
                ToastUtils.get().shortToast("MoreTwo---" + (item.type == 0 ? "A" : "B"));
            }
        })).with(new MoreB().setOnItemClickListener(new OnItemClickListener<MoreTwoBean>() {
            @Override
            public void onItemClick(int position, MoreTwoBean item) {
                ToastUtils.get().shortToast("MoreTwo---" + (item.type == 0 ? "A" : "B"));
            }
        }));
    }

    @Override
    protected Class withLinker(MoreTwoBean item) {
        if (item.type == 0){
            return MoreA.class;
        }else if (item.type ==1){
            return MoreB.class;
        }else {
            return null;
        }
    }

    public static class MoreA extends ItemViewProvider<MoreTwoBean> {

        @Override
        protected void convert(@NonNull MultiItemViewHolder holder, @NonNull MoreTwoBean item, int position) {
            TextView tv = holder.getView(R.id.tv_name_ma);
            tv.setText("MoreTwoA---" + (item.type == 0 ? "A" : "B"));
        }

        @Override
        protected int getItemLayoutId() {
            return R.layout.item_mul_one_ma;
        }

        @Override
        public void onDestroy() {
            super.onDestroy();
            LogUtils.e("fanly", "MoreTwoA destroy()");
        }
    }
    public static class MoreB extends ItemViewProvider<MoreTwoBean> {

        @Override
        protected void convert(@NonNull MultiItemViewHolder holder, @NonNull MoreTwoBean item, int position) {
            TextView tv = holder.getView(R.id.tv_name_mb);
            tv.setText("MoreTwoB---" + (item.type == 0 ? "A" : "B"));
        }

        @Override
        protected int getItemLayoutId() {
            return R.layout.item_mul_one_mb;
        }

        @Override
        public void onDestroy() {
            super.onDestroy();
            LogUtils.e("fanly", "MoreTwoB destroy()");
        }
    }


}
